import java.util.*;

 class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
     public ListNode ReverseList(ListNode head) {
         if(head == null){
             return null;
         }
         if(head.next == null){
             return head;
         }
         ListNode slow = head;
         ListNode fast = head.next;
         ListNode fastNext = fast.next;
         while(fast != null){
             fast.next = slow;
             slow = fast;
             fast = fastNext;
             fastNext = fastNext.next;
         }
         head.next = null;
         return slow;
     }
}
public class Solution {
    public static void main(String[] args) {
        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode3 = new ListNode(3);
        ListNode listNode4 = new ListNode(4);
        ListNode listNode5 = new ListNode(5);
        System.out.println(listNode1.ReverseList(listNode1).toString());
    }

}